#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : aimix
@File    : clip_worker.py
@IDE     : PyCharm
@Author  : admin
@Date    : 2025/4/14 12:28
"""
import traceback
from PyQt5.QtCore import QThread, pyqtSignal
from core.video.clip import *



class ClipVideoQtThread(QThread):
    """分镜视频桥接器"""
    failed = pyqtSignal(Exception)


    def __init__(self, channel, input_files, output_folder, arg=None, parent=None):
        super(ClipVideoQtThread, self).__init__()
        self.channel = channel
        self.input_files = input_files
        self.output_folder = output_folder
        self.arg = arg


    def run(self):
        try:
            tasks = []

            if self.channel == 'duration':
                for file in self.input_files:
                    tasks.append((file, self.output_folder, int(self.arg)))
                batch_clip_video_by_duration(tasks, max_workers=4)
            elif self.channel == 'count':
                for file in self.input_files:
                    tasks.append((file, self.output_folder, int(self.arg)))

                batch_clip_video_by_shots(tasks, max_workers=4)
            elif self.channel == 'voice':
                for file in self.input_files:
                    tasks.append((file, self.output_folder))
                batch_clip_video_by_audio(tasks, max_workers=4)
            elif self.channel == 'scene':
                for file in self.input_files:
                    tasks.append((file, self.output_folder, float(self.arg)))
                batch_clip_video_by_transition(tasks, max_workers=4)
            else:
                pass
        except Exception as e:
            traceback.print_exc()
            self.failed.emit(e)

